package exercise;

import java.util.Random;
import java.util.Scanner;

public class ApiDay1_1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Random random = new Random();
        String line = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        System.out.println("请输入你的密码长度：");
        int len = scan.nextInt();
        scan.nextLine();
        String code = "";
        for (int i=0;i<len;i++){
            int num = random.nextInt(line.length());
            char c = line.charAt(num);
            code +=c;
        }
        System.out.println("密码："+code);
        System.out.print("请输入你的密码：");
        String answer = scan.nextLine();
        if(code.equalsIgnoreCase(answer)){
            System.out.println("密码正确");
        }else{
            System.out.println("密码错误");
        }
    }
}
